package com.abc.controller;

import com.abc.common.Result;
import com.abc.dto.request.FileParseRequest;
import com.abc.dto.response.FileParseResultResponse;
import com.abc.dto.response.FileParseTaskResponse;
import com.abc.service.ZhiPuFileParserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Validated
@RestController
@RequestMapping("/file-parser")
@Tag(name = "文件解析", description = "ZhiPu AI 文件解析相关接口")
public class FileParserController {

    @Autowired
    private ZhiPuFileParserService fileParserService;


    @PostMapping(value = "/create", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "创建文件解析任务", description = "上传文件并创建解析任务")
    public Result<FileParseTaskResponse> createParseTask(@Valid FileParseRequest request) {
        FileParseTaskResponse response = fileParserService.createParseTask(request);
        return Result.success(response);
    }

    @GetMapping("/result/{taskId}/text")
    @Operation(summary = "获取文件解析结果（文本格式）", description = "根据任务ID获取解析后的文本内容")
    public Result<FileParseResultResponse> getParseResult(@PathVariable("taskId") String taskId) {
        FileParseResultResponse response = fileParserService.getParseResult(taskId);
        return Result.success(response);
    }

    @GetMapping("/result/{taskId}/download")
    @Operation(summary = "获取文件解析结果（下载链接格式）", description = "根据任务ID获取解析结果的下载链接")
    public Result<FileParseResultResponse> getParseResultWithDownloadLinks(@PathVariable("taskId") String taskId) {
        FileParseResultResponse response = fileParserService.getParseResultWithDownloadLinks(taskId);
        return Result.success(response);
    }
}